function e(e, t, n) {
    return t in e ? Object.defineProperty(e, t, {
        value: n,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = n, e;
}

var t, n = getApp(),
    o = require("../../../utils/function.js"),
    i = (require("../../../data/mockData.js"),
        require("../../../api.js"));

require("../../../siteinfo.js"), wx.getStorageSync("openId");

Page({
    data: (
        t = {
            money: 0,
            coupon_num: 0,
            
            des_limit: !1,
            isOpen: !1,
            user_info: {
                nickname: ""
            },
            copyright: "",
            copyright_rule: "",
            avatar: "/images/user/icon-07.png",
            longitude: 108.93,
            latitude: 32.28,
            mapWidth: 100,
            markers: [{
                iconPath: "../../../images/icon/icon-20.png",
                id: 0,
                latitude: 32.27,
                longitude: 108.93,
                width: 20,
                height: 20
            }],
            polyline: [{
                points: [{
                    longitude: 108.93,
                    latitude: 32.28
                }, {
                    longitude: 108.94,
                    latitude: 32.27
                }],
                color: "#FF0000DD",
                width: 2,
                dottedLine: !0
            }],
            controls: [{
                id: 1,
                iconPath: "../../../images/icon/icon-22.png",
                position: {
                    left: 34,
                    top: 33,
                    width: 50,
                    height: 50
                },
                clickable: !0
            }],
            caidan:0,
            scrollLeft: 0,
            zuoyou: "icon-zuoyou"
        }, e(t, "avatar", "../../../images/icon/icon-07.png"), e(t, "buttonText", "一键授权登录"),
        e(t, "username", "未登录"), e(t, "is_login", !1), e(t, "button_loading", !1), e(t, "driver_text", "司机招募"),
        e(t, "driver_url", "../../driver/driverAgreement/driverAgreement"), t),
    onLoad: function (e) {

        this.getlocation(), e.uid && n.shareCouponsMessage(e.uid), e.scene && wx.setStorageSync("scene", e.scene);
        console.log(e);
    },
    scrollLeftHandler: function () {
        0 === this.data.scrollLeft ? this.setData({
            scrollLeft: -650,
            zuoyou: "icon-zuoyou1",
            mapWidth: 750
        }) : this.setData({
            scrollLeft: 0,
            zuoyou: "icon-zuoyou",
            mapWidth: 100
        });
    },
    login_out: function () {
        var e = this;
        wx.showModal({
            title: "温馨提示",
            content: "确定要退出当前账号吗",
            success: function (t) {
                if (t.confirm) {
                    try {
                        wx.clearStorageSync();
                    } catch (e) {}
                    e.setData({
                        user_info: "",
                        is_login: !1
                    }), wx.showToast({
                        title: "退出成功",
                        icon: "none"
                    }), setTimeout(function () {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 1e3);
                } else t.cancel;
            }
        });
    },
    driver_btn_func: function (e) {
        console.log(e);
        n.request({
            url: "https://dishichuxing.cn/api.php/?s=promise_money/index",
            method: "post",
            data: {},
            success: (res)=> {
                if(res.data.status==1){
                    var t = e.detail.formId;
                    // console.log(t);
                    if (n.PushfromId(t), "" == this.data.user_info.nickname) return n.showToast("请先登录", 0, 1e3, function () { n.navTo("/pages/logs/logs");}), !1;
                    if (this.data.user_info.phone) {
                        var o = e.currentTarget.dataset.skip;
                        console.log(o);
                        
                        if ("shenhezhong" != o)
                            if ("weitongguo" != o) "chongxinshenghe" == o && wx.navigateTo({
                                url: "/pages/driver/personalInformation/personalInformation"
                            }), wx.navigateTo({
                                url: o
                            });

                            else {
                                var i = this.data.driver_btn_why;
                                wx.showModal({
                                    title: "提示",
                                    content: i
                                });
                            }
                        else wx.showToast({
                            title: "资料审核中",
                            icon: "none",
                            duration: 5e3
                        });
                    } else wx.navigateTo({
                        url: "/pages/logs/logs"
                    });
                }else{
                    wx.redirectTo({
                        url: "/pages/index/index"
                    })
                }
               console.log(t)
            }
        });
        return false
        
    },
    getcopyright: function () {
        var e = this;
        n.request({
            url: i.user.getcopyright,
            method: "post",
            data: {},
            success: function (t) {
                1 == t.code && e.setData({
                    copyright: t.data.copyright,
                    copyright_rule: t.data.copyright_rule
                });
            }
        });
    },
    login_succ_func: function (e) {
        var t = this,
            o = this;
        new Promise(function (e, t) {
            n.request({
                url: i.driver.getstatus,
                method: "post",
                data: {},
                success: function (t) {
                   console.log(t)
                    1 == t.code ? (wx.setStorageSync("usertype", t.data.type), o.setData({
                        serverPhone: t.data.serverphone,
                        money: t.data.price,
                        coupon_num: t.data.coupon_num
                    }), e(t.data)) : wx.showToast({
                        title: "申请状态获取失败",
                        icon: "none"
                    });
                }
            });
        }).then(function (e) {
            console.log(e);
            var n = e.type,
                o = e.audit,
                i = e.is_complete,
                a = e.is_margin,
                s = e.applyfor;
            if (1 == n)
                if (1 == i) switch (o += "") {
                    case "0":
                        t.setData({
                            driver_btn: {
                                text: "审核中",
                                url: "shenhezhong"
                            }
                        });
                        break;

                    case "1":
                        1 == a ? t.setData({
                            driver_btn: {
                                text: "司机入口",
                                url: "/pages/index/index"
                            }
                        }) : t.setData({
                            driver_btn: {
                                text: "交纳保证金",
                                url: "/pages/driver/userauth-pay/index"
                            }
                        });
                        break;

                    case "2":
                        1 == s ? t.setData({
                            driver_btn: {
                                text: "司机招募",
                                url: "weitongguo"
                            },
                            driver_btn_why: e.why
                        }) : t.setData({
                            driver_btn: {
                                text: "重新审核",
                                url: "chongxinshenghe"
                            }
                        });
                } else t.setData({
                    driver_btn: {
                        text: "完善司机信息",
                        url: "/pages/driver/personalInformation/personalInformation"
                    }
                });
                else t.setData({
                    driver_btn: {
                        text: "司机招募",
                        url: "/pages/driver/driverAgreement/driverAgreement"
                    }
                });
        }), this.setData({
            is_login: !0,
            user_info: e,
            button_loading: !1
        });
    },
    loginHandler: function (e) {
        wx.removeStorageSync("access_token");
        var t = this;
        wx.showLoading(), this.setData({
            button_loading: !0
        }), wx.login({
            success: function (e) {
                e.code && wx.getUserProfile({
                    success: function (o) {
                        wx.hideLoading(), n.request({
                            url: i.user.login,
                            method: "post",
                            data: {
                                code: e.code,
                                iv: o.iv,
                                encryptedData: o.encryptedData
                            },
                            success: function (e) {
                                1 == e.code ? (wx.showToast({
                                        title: "登录成功",
                                        icon: "success",
                                        duration: 2e3
                                    }), wx.setStorageSync("user_info", e.data), wx.setStorageSync("access_token", e.data.access_token),
                                    t.login_succ_func(e.data)) : (wx.removeStorage({
                                    key: "access_token"
                                }), wx.showToast({
                                    title: "登录失败",
                                    icon: "none",
                                    duration: 2e3
                                }));
                            }
                        });
                    }
                });
            }
        });
    },
    relstiveServerHandler: function () {
        o.callPhoneHandler(this.data.serverPhone);
    },
    navTo: function (e) {
        n.navTo(e.currentTarget.dataset.url);
    },
    intoPageHandler: function (e) {
        var t = e.detail.formId;
        if (n.PushfromId(t), "" == this.data.user_info.nickname) return n.showToast("请先登录", 0, 1e3, function () {
            n.navTo("/pages/logs/logs");
        }), !1;
        if (this.data.user_info.phone)
            if ("../../distributionLogin/distributionLogin" != e.currentTarget.dataset.skip) wx.navigateTo({
                url: e.currentTarget.dataset.skip
            });
            else {
                n.request({
                    url: i.user.distribution_state,
                    method: "post",
                    data: {},
                    success: function (e) {
                        0 == e.code ? wx.showModal({
                            title: e.msg,
                            content: "是否申请成为分销商！",
                            success: function (e) {
                                e.confirm ? wx.navigateTo({
                                    url: "../../distributionLogin/distributionLogin"
                                }) : e.cancel;
                            }
                        }) : 1 == e.code ? wx.navigateTo({
                            url: "../../distributionCenter/distributionCenter"
                        }) : 2 == e.code ? wx.showToast({
                            title: e.msg,
                            icon: "none",
                            duration: 2e3
                        }) : 3 == e.code ? wx.showModal({
                            title: "提示",
                            content: e.msg + "," + e.data.reason + ",是否重新申请成为分销商！",
                            success: function (e) {
                                e.confirm ? wx.navigateTo({
                                    url: "../../distributionLogin/distributionLogin"
                                }) : e.cancel;
                            }
                        }) : (e.code, wx.showToast({
                            title: e.msg,
                            icon: "none",
                            duration: 2e3
                        }));
                    }
                });
            }
        else wx.navigateTo({
            url: "/pages/logs/logs"
        });
    },
    callPhoneHandler: function () {
        wx.makePhoneCall({
            phoneNumber: wx.getStorageSync("serverPhone")
        });
    },
    getlocation: function () {
        var e = this;
        wx.getLocation({
            type: "gcj02",
            success: function (t) {
                var n = t.latitude,
                    o = t.longitude;
                t.speed, t.accuracy;
                e.setData({
                    latitude: n,
                    longitude: o
                });
            }
        });
    },
    onReady: function () {},
    onShow: function () {
        if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: 3
        })
      }
        this.getJurisdiction(), this.getInvoice(), this.getcopyright();
        var e = wx.getStorageSync("user_info");
        console.log(e)
        e ? this.login_succ_func(e) : this.setData({
            driver_btn: {
                text: "司机招募",
                url: "shenhezhong"
            }
        });
    },
    torecommendation:function(e){
        var p =   e.currentTarget.dataset.skip
        wx.navigateTo({
          url: p,
        })
    },
    getInvoice: function () {
        var e = this;
        n.request({
            url: i.default.invoice,
            method: "post",
            data: {},
            success: function (t) {
                if (1 == t.code) {
                    var n = 1 == t.data.open_invoice;
                    e.setData({
                        des_limit: n
                    });
                }
            }
        });
    },
    caidan:function(){
        var that = this
        this.data.caidan == 10 && wx.showModal({
            title:'zyh',
            content:'你发现了德子和赵信',
          cancelColor: 'cancelColor',
          success(res) {
                that.setData({
                    caidan: 0  
                })
          }
        })
        console.log(this.data.caidan);
       this.setData({
           caidan:this.data.caidan + 1
       })
    },
    getJurisdiction: function () {
        var e = this;
        n.request({
            url: i.distribution.plugs_list,
            method: "post",
            data: {},
            success: function (t) {
                1 == t.code && "1" == t.data.distribution.is_open && 1 == t.data.distribution.open_distribution ? e.setData({
                    isOpen: !0
                }) : e.setData({
                    isOpen: !1
                });
            }
        });
    },
    scrollLeft: function (e) {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function () {
        return {
            title: n.shareAppMessage().title,
            imageUrl: n.shareAppMessage().imageUrl,
            desc: n.shareAppMessage().desc,
            path: n.shareAppMessage().path
        };
    }
});